﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace TestVdataAdapter.PriceServerAdapter
{
    [TestClass]
    public class TestFooPriceServerEventHandler
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        private Dictionary<string, PriceLibrary.PriceService.StockBase>  _basePrices;

        private Dictionary<string, PriceLibrary.PriceService.StockBase> _top3Prices;

        private Dictionary<int, PriceLibrary.PriceService.StockBase> _marketInfos;

        private List<PriceLibrary.PriceService.StockInfoDyns> _putThroughTopPrices;

        private List<PriceLibrary.PriceService.Transaction> _putThroughTransactions;

        //Use TestInitialize to run code before running each test
        [TestInitialize()]
        public void MyTestInitialize()
        {
            _basePrices = new Dictionary<string, PriceLibrary.PriceService.StockBase>();
            _basePrices.Add("VND", new PriceLibrary.PriceService.StockBase());
            _basePrices.Add("SSI", new PriceLibrary.PriceService.StockBase());

            _top3Prices = new Dictionary<string, PriceLibrary.PriceService.StockBase>();
            _top3Prices.Add("FPT", new PriceLibrary.PriceService.StockBase());
            _top3Prices.Add("KLS", new PriceLibrary.PriceService.StockBase());

            _marketInfos = new Dictionary<int, PriceLibrary.PriceService.StockBase>();
            _marketInfos.Add(10, new PriceLibrary.PriceService.StockBase());
            _marketInfos.Add(11, new PriceLibrary.PriceService.StockBase());

            _putThroughTopPrices = new List<PriceLibrary.PriceService.StockInfoDyns>();
            var topPrice = new PriceLibrary.PriceService.StockInfoDyns(); topPrice.StockSymbol = "VND";
            _putThroughTopPrices.Add(topPrice);
            topPrice = new PriceLibrary.PriceService.StockInfoDyns(); topPrice.StockSymbol = "SSI";
            _putThroughTopPrices.Add(topPrice);

            _putThroughTransactions = new List<PriceLibrary.PriceService.Transaction>();
            var transaction = new PriceLibrary.PriceService.Transaction(); transaction.Symbol = "VND";
            _putThroughTransactions.Add(transaction);
            transaction = new PriceLibrary.PriceService.Transaction(); transaction.Symbol = "SSI";
            _putThroughTransactions.Add(transaction);

        }

        [TestMethod]
        public void TestFooGetFirtime()
        {
            FooPriceServerEventHandler foo = new FooPriceServerEventHandler();

            List<string> expected = new List<string>(){"<GetFirstTime>", 
                "<BasePrices>", 
                "<Item>VND</Item>", "<Item>SSI</Item>", 
                "</BasePrices>", 
                "<Top3Prices>", 
                "<Item>FPT</Item>", "<Item>KLS</Item>", 
                "</Top3Prices>",
                "</GetFirstTime>" };

            foo.GetFirstTime(_basePrices, _top3Prices);

            List<string> data = foo.Data;

            Assert.AreEqual(expected.Count, data.Count, "Foo does not produce the same number of message");

            for (int i = 0; i < data.Count; i++)
            {
                Assert.AreEqual(expected[i], data[i], "Messages in list are mismatched");
            }
        }

        [TestMethod()]
        public void TestFooTop3PricesChanged()
        {
            FooPriceServerEventHandler foo = new FooPriceServerEventHandler();

            foo.Top3PricesStock_Changed(_top3Prices);
            
            List<string> data = foo.Data;

            List<string> expected = new List<string>(){"<Top3PricesStockChanged>",   
                "<Top3Prices>", 
                "<Item>FPT</Item>", "<Item>KLS</Item>", 
                "</Top3Prices>",
                "</Top3PricesStockChanged>" };

            Assert.AreEqual(expected.Count, data.Count, "Top3PricesChanged: Foo does not produce the same number of message");

            for (int i = 0; i < data.Count; i++)
            {
                Assert.AreEqual(expected[i], data[i], "Top3PricesChanged: Messages in list are mismatched");
            }
        }

        /// <summary>
        /// Foo should add to data list of marketinfo wrap with tag <MarketInfoChanged>
        /// </summary>
        [TestMethod()]
        public void TestFoodMarketInfoChange()
        {
            FooPriceServerEventHandler foo = new FooPriceServerEventHandler();

            foo.MarketInfo_Changed(_marketInfos);

            List<string> data = foo.Data;

            List<string> expected = new List<string>(){"<MarketInfoChanged>",                   
                "<Item>10</Item>", "<Item>11</Item>",                 
                "</MarketInfoChanged>" };

            Assert.AreEqual(expected.Count, data.Count, "MarketInfoChange: Foo does not produce the same number of message");

            for (int i = 0; i < data.Count; i++)
            {
                Assert.AreEqual(expected[i], data[i], "MarketInfoChange: Messages in list are mismatched");
            }
        }

        /// <summary>
        /// Foo should add to data list of PutThroughTopPrices wrap with tag <PutThroughTopPrices>
        /// </summary>
        [TestMethod()]
        public void TestFooPutThroughTopPrices()
        {
            FooPriceServerEventHandler foo = new FooPriceServerEventHandler();

            foo.PutThroughTopPrices_Changed(_putThroughTopPrices);

            List<string> data = foo.Data;

            List<string> expected = new List<string>(){"<PutThroughTopPrices>",                  
                "<Item>VND</Item>", "<Item>SSI</Item>",                 
                "</PutThroughTopPrices>" };

            Assert.AreEqual(expected.Count, data.Count, "MarketInfoChange: Foo does not produce the same number of message");

            for (int i = 0; i < data.Count; i++)
            {
                Assert.AreEqual(expected[i], data[i], "MarketInfoChange: Messages in list are mismatched");
            }
        }

        /// <summary>
        /// Foo should add to data list of PutThroughTransactions wrap with tag <PutThroughTransactions>
        /// </summary>
        [TestMethod()]
        public void TestFooPutThroughTransactions()
        {
            FooPriceServerEventHandler foo = new FooPriceServerEventHandler();

            foo.PutThroughTransactions_Changed(_putThroughTransactions);

            List<string> data = foo.Data;

            List<string> expected = new List<string>(){"<PutThroughTransactions>",                  
                "<Item>VND</Item>", "<Item>SSI</Item>",                 
                "</PutThroughTransactions>" };

            Assert.AreEqual(expected.Count, data.Count, "MarketInfoChange: Foo does not produce the same number of message");

            for (int i = 0; i < data.Count; i++)
            {
                Assert.AreEqual(expected[i], data[i], "MarketInfoChange: Messages in list are mismatched");
            }
        }
     
    }
}
